package LeetcodeTest_fourteen;

import java.util.ArrayList;
import java.util.Collections;

public class HashSet
{
    public static void main(String[] args)
    {
        MyHashSet myHash=new MyHashSet();
        myHash.add(1);
        myHash.add(2);
        System.out.println(myHash.contains(1));
        System.out.println(myHash.contains(3));
        myHash.add(2);
        System.out.println(myHash.contains(2));
        myHash.remove(2);
        System.out.println(myHash.contains(2));
    }
}
class MyHashSet
{

    /** Initialize your data structure here. */
    public ArrayList<Boolean> HashSets;
    public MyHashSet()
    {
        //初始化链表，Collections.nCopies(int n,Object o),拷贝对象o n次，填充链表
        HashSets=new ArrayList<Boolean>(Collections.nCopies(1000001,false));
    }
    public void add(int key)
    {
        if(!HashSets.get(key))
            HashSets.set(key,true);
    }
    public void remove(int key)
    {
        if(HashSets.get(key)==true)
            HashSets.set(key,false);
    }
    /** Returns true if this set contains the specified element */
    public boolean contains(int key)
    {
        if(HashSets.get(key))
            return true;
        else
            return false;
    }
}
/**
 * Your MyHashSet object will be instantiated and called as such:
 * MyHashSet obj = new MyHashSet();
 * obj.add(key);
 * obj.remove(key);
 * boolean param_3 = obj.contains(key);
 */